// <button type="button" id="sensor-button" class="btn btn-default
// ">Account</button>
// <button type="button" id="photo-button" class="btn
// btn-default">Settings</button>
//
//

function onSuccessGeoLocation(position) {
	var latlng = new google.maps.LatLng(position.coords.latitude,
			position.coords.longitude);

	var anchor = document.querySelector("#upload-observation-button");
	anchor.href += "#@" + position.coords.latitude + ","
			+ position.coords.longitude;
	var mapOptions = {
		zoom : 12,
		center : latlng
	};

	var map = new google.maps.Map(document.getElementById('map-canvas'),
			mapOptions);

	var menuButtons = document.querySelector("#menu-buttons");
	menuButtons.className = "btn-group";
	map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(menuButtons);

	// var marker = new google.maps.Marker({
	// position : latlng,
	// map : map
	// });
	load_heatmap(map, position.coords.latitude, position.coords.longitude);
}

function initialize() {
	if ("geolocation" in navigator) {
		var geo_options = {
			enableHighAccuracy : true,
			maximumAge : 30000,
			timeout : 27000
		};
		navigator.geolocation.getCurrentPosition(onSuccessGeoLocation, null,
				geo_options);
	} else {
		/* geolocation IS NOT available */
	}
}

function load_heatmap(map, lat, lng) {
	var heatMapData = [];
	for (var i = 0; i < 100/* 1000/zoom */; i++) {
		heatMapData.push({
			location : new google.maps.LatLng(
					lat + (Math.random() / 50) - .005, lng + Math.random() / 50
							- .005),
			weight : /* Math.random() * 1 */2
		})
	}
	heatMapData.push({
		location : new google.maps.LatLng(lat + (Math.random() / 50) - .005,
				lng + Math.random() / 50 - .005),
		weight : /* Math.random() * 1 */20
	})
	heatMapData.push({
		location : new google.maps.LatLng(lat + (Math.random() / 50) - .005,
				lng + Math.random() / 50 - .005),
		weight : /* Math.random() * 1 */20
	})

	heatmap = new google.maps.visualization.HeatmapLayer({
		data : heatMapData,
		gradient : [
				"rgba(0, 255, 255, 0)"/* first one should be transparent */,
				"rgba(156, 255, 156, 0.6)", "rgba(49, 255, 0, 0.6)",
				"rgba(49, 207, 0, 0.6)", "rgba(255, 255, 0, 0.6)",
				"rgba(255, 207, 0, 0.6)", "rgba(255, 154, 0, 0.6)",
				"rgba(255, 100, 100, 0.6)", "rgba(255, 0, 0, 0.6)",
				"rgba(153, 0, 0, 0.6)", "rgba(206, 48, 255, 0.6)" ],
		// radius : 20,
		opacity : 1

	});
	heatmap.setMap(map);

}

google.maps.event.addDomListener(window, 'load', initialize);